﻿using System.Diagnostics;
using Avalonia.Controls;
using Avalonia.Interactivity;
using DevManager.Models;
using DevManager.Services;
using DevManager.ViewModels.Pages;
using DevManager.Views;

namespace DevManager.Pages;

public partial class HomePage : PageBase
{
    public HomePage()
    {
        InitializeComponent();
        DataContext = new HomePageModel();
    }

    private void NavClick(object? sender, RoutedEventArgs e)
    {
        if (sender is not Button { DataContext: NavModel pg }) return;
        try
        {
            var s = pg.NavigateURI.Split("://");
            if(s.Length < 1)return;
            if (s[0] is "https" or "http")
            {
                Process.Start(new ProcessStartInfo(pg.NavigateURI)
                    { UseShellExecute = true, Verb = "open" });
                return;
            }

            var main = ViewService.GetView<MainView>(this);
            if(main == null)return;
            main.Navigate(pg.NavigateURI);
        }
        catch
        {
            //
        }
        finally
        {
            e.Handled = true;
        }
    }
}